package com.flex.core.util.img
{
	import com.flex.core.model.img.Mimage;
	
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.net.URLStream;
	
	import mx.controls.Alert;

	public class ImgUtils
	{
		public function ImgUtils()
		{
		}

		/**
		 * get image info by Loader with URLRequest, may throw error exception,
		 * this function trys to get imageInfo by request,and then dispacth terminal function
		 */
		public static function getImage(imgUrl:String, imgCompleteEvent:String):Mimage
		{
			try
			{
				var loader:Loader=new Loader();
				var img:Mimage=new Mimage(imgCompleteEvent);
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void
				{
					img.source=imgUrl;
				});
				//这里说一个技巧  当url 中有中文字体的话 使用encodeURI方法 如果没有 则可以不加
				loader.load(new URLRequest(encodeURI(imgUrl)));
			}
			catch (err:Error)
			{
				Alert.show("img connection error:" + err.message);
			}
			return img;
		}

	}
}